<?php

    class Pictures_model extends MY_Model
    {
        function __construct()
        {
            parent::__construct();
            $this->table = 'pictures';
        }
        
        function find_pictures($gallery_id,$limit=NULL)
        {
            $q = "
            SELECT gallery.path as path, pictures.*
            FROM gallery
            LEFT JOIN pictures on gallery.ID = pictures.gallery_ID  
            WHERE gallery.ID = $gallery_id
            ORDER BY pictures.order ASC, pictures.ID ASC
            ";
            
            if(isset($limit)) $q .= "LIMIT $limit";
            
            $res = $this->db->query($q)->result_array();
            return $res;
        }
        
        function find_picture_column($picture_id)
        {
            $q = "
            SELECT *
            FROM pictures 
            WHERE ID = $picture_id
            ";
            $res = $this->db->query($q)->row_array();
            return $res;
        }

    }

?>
